package mytool;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Xiexinlin on 2015-11-3.
 * list数据处理工具类
 */
public class Data {

    public String toJson(List<Map<String, Object>> In) {
        if (In.size() <= 0) return "";
        return JSON.toJSONString(In);
    }
    public String toJson_Itude(List<Itude> In) {
        if (In.size() <= 0) return "";
        return JSON.toJSONString(In);
    }
    public String toJson2(List<String> In) {
        if (In.size() <= 0) return "";
        return JSON.toJSONString(In);
    }
    public List<Map<String, Object>> toListMap(String In) {
        if (In.equals("") || In == null) return new ArrayList<>();
        return JSON.parseObject(In, new TypeReference<List<Map<String, Object>>>() {
        });
    }  public List<Itude> toListMap_Itude(String In) {
        if (In.equals("") || In == null) return new ArrayList<>();
        return JSON.parseObject(In, new TypeReference<List<Itude>>() {
        });
    }
    public List<String> toListMap_String(String In) {
        if (In.equals("") || In == null) return new ArrayList<>();
        return JSON.parseObject(In, new TypeReference<List<String>>() {
        });
    }

    public Boolean getMoreDATA(List<Itude> IN, Itude RE) {
        int delect = -1;
        int num = IN.size();
        for (int i = 0; i < num; i++) {
            Itude data = IN.get(i);
            if (data.getLatitude()== RE.getLatitude()&&data.getLongitude()== RE.getLongitude()) {
                delect = i;
            }
        }
        if (delect != -1) {
            IN.remove(delect);
        }

        return true;
    }

}
